package com.rjxy.plansystemmanagement.controller.yh;

import com.rjxy.plansystemmanagement.entity.Result.Result;
import com.rjxy.plansystemmanagement.entity.yh.YhCode;
import com.rjxy.plansystemmanagement.entity.yh.YhCoupon;
import com.rjxy.plansystemmanagement.entity.yh.YhUser;
import com.rjxy.plansystemmanagement.service.YhService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/Yh")
public class YhController {
    @Autowired
    private YhService yhService;

    /**
     * 查询所有已发放优惠券
     * @return
     */
    @GetMapping("/Issued")
    public Result IssuedList(){
        log.info("查询已发放优惠券列表");
        List<YhCoupon> yhCouponList = yhService.getIssuedCoupon();
        return Result.success(yhCouponList);
    }

    @PostMapping("/addYhUser")
    public Result addYhUser(@RequestBody YhUser yhUser){
        yhService.addYhUser(yhUser);
        return Result.success();
    }

    @GetMapping("/getCouponByUid/{id}")
    public Result getCouponByUid(@PathVariable Integer id){
        List<YhCoupon> yhCouponList = yhService.getCouponByUid(id);
        return Result.success(yhCouponList);
    }

    @GetMapping("/selectCode/{code}")
    public Result selectCode(@PathVariable String code){
        YhCode yhCode = yhService.selectCode(code);
        return Result.success(yhCode);
    }

    @PutMapping("/updateYhCode")
    public Result updateYhCode(@RequestBody YhCode yhCode){
        yhService.updateYhCode(yhCode);
        return Result.success();
    }

    @GetMapping("/getYhUserByStatus/{status}")
    public Result getYhUserByStatus(@PathVariable Integer status){
        List<YhUser> yhUserList = yhService.getYhUserByStatus(status);
        return Result.success(yhUserList);
    }

    @GetMapping("/getCouponsByCouponId/{id}")
    public Result getCouponsByCouponId(@PathVariable Integer id){
        List<YhCoupon> yhCouponList = yhService.getCouponsByCouponId(id);
        return Result.success(yhCouponList);
    }
}
